/********************************
 *版权所有 CopyRight(c) 快程乐码信息有限公司所有，未经授权，不得复制、转发
 */
package com.yjx.test.dozer.converterClazz;

import org.dozer.DozerConverter;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/************
 *@Author yejx
 *@version v1.0
 *@create 2020/6/30 16:47
 *@Description LocalDateTime 和 Date 转换器
 *
 */
public class LocalDateTimeToDateConverter extends DozerConverter<LocalDateTime, Date> {

    public LocalDateTimeToDateConverter() {
        super(LocalDateTime.class, Date.class);
    }

    /**
     * LocalDateTime 转换成    Date
     *
     * @param source
     * @param destination
     * @return LocalDateTime
     */
    @Override
    public LocalDateTime convertFrom(Date source, LocalDateTime destination) {
        return LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
    }

    /**
     * Date 转换成  LocalDateTime
     *
     * @param source
     * @param destination
     * @return Date
     */
    @Override
    public Date convertTo(LocalDateTime source, Date destination) {
        return Date.from(source.atZone(ZoneId.systemDefault()).toInstant());
    }

}
